package com.night;


import com.night.annotation.ComponentScan;
import com.night.context.AnnotationConfigApplicationContext;
import com.night.ibatis.MapperProxyFactory;
import com.night.io.PropertyResolver;
import com.night.test.BaseMapper;
import com.night.test.User;
import com.night.test.UserMapper;

import java.util.List;
import java.util.Properties;

@ComponentScan
public class SpringSourceApplication {

    public static void main(String[] args) {

//        Properties properties = new Properties();
//        properties.put("datasource.url", "jdbc:mysql://localhost:3306/test?useUnicode=true&allowPublicKeyRetrieval=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8&allowMultiQueries=true");
//        properties.put("datasource.username", "root");
//        properties.put("datasource.password", "root");
//        properties.put("datasource.driver-class-name", "com.mysql.cj.jdbc.Driver");
//        properties.put("app.name", "com.mysql.cj.jdbc.Driver");
//        PropertyResolver propertyResolver = new PropertyResolver(properties);
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringSourceApplication.class, propertyResolver);

//        JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);

//        User user = jdbcTemplate.queryForObject("select username, password from t_user where id = ?", User.class, 1);
//        System.out.println(user.toString());

//        String updateSql = "update t_user set password = ? where username = ?";
//
//        jdbcTemplate.update(updateSql, "tony", "tony");

//        UserService userService = context.getBean(UserService.class);

//        userService.update("tony", "111");

//        UserMapper userMapper = context.getBean(UserMapper.class);
//        List<User> users = userMapper.getUsers("admin");
//
//        users.forEach(System.out::println);
//
//        System.out.println("=================");
//
//        System.out.println(userMapper.getOneByUsernameAndNickName("admin", "小鱼同学"));
//        BaseMapper baseMapper = context.getBean(BaseMapper.class);
//        List<User> users = baseMapper.getUsers("admin");
//
//        System.out.println(users.size());
//        users.forEach(System.out::println);


        BaseMapper baseMapper = MapperProxyFactory.getMapper(BaseMapper.class);
        System.out.println(baseMapper.getUsers("admin"));
    }

}
